package isssr.dao.src;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateDAOFactory extends DAOFactory {


	private static final SessionFactory sessionFactory = buildSessionFactory();
	
	private static SessionFactory buildSessionFactory() {
		if(HibernateDAOFactory.sessionFactory!=null) 
			return HibernateDAOFactory.sessionFactory;
		
        try {
        	Configuration cfg =new Configuration();
            return cfg.configure().buildSessionFactory();
        }
        catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
	
	@Override
	public UserDAO getUserDAO() {
		// TODO Auto-generated method stub
		return new HibernateUserDAO(this.sessionFactory);
	}
	
	@Override
	public RoleDAO getRoleDAO()
	{
		return new HibernateRoleDAO();
	}

	@Override
	public OrganizationalGoalDAO getOrganizationalGoalDAO() {
		// TODO Auto-generated method stub
		return new HibernateOrganizationalGoalDAO();
	}
}
